using ManagoMes.Read.API.Commonts;
using MangoMes.Commont.DBContext;
using MangoMes.Commont.Infrastructures.Interfaces;
using MangoMes.Commont.Infrastructures.Repository;
using MangoMes.Write.API.Applications.Login;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddServices(builder.Configuration);
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();

builder.Services.AddSwaggerGen(x =>
{
    var path = AppDomain.CurrentDomain.BaseDirectory + "ManagoMes.Read.API.xml";
    x.IncludeXmlComments(path, true);
});


//builder.Services.AddDbContext<EFDBContext>(x => x.UseMySql(builder.Configuration.GetConnectionString("DB"), new MySqlServerVersion("8.4.2")));
builder.Services.AddAutoMapper(typeof(AutoMapperHelper));
builder.Services.AddScoped<Logincommonality>();
builder.Services.AddScoped(typeof(IBateRepository<>), typeof(BateRepository<>));
builder.Services.ConsulRegister(option =>
{
    var consuConfig = builder.Configuration.GetSection("ConsulConfig").Get<ConsulConfig>();
    consuConfig.ServicePort = int.Parse(builder.Configuration["port"] ?? "5000");

    option.Config(consuConfig);
});
var app = builder.Build();

// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
//{
    app.UseSwagger();
    app.UseSwaggerUI();
//}

app.UseAuthorization();
app.UseConsul(builder.Services.BuildServiceProvider(), app.Lifetime);
app.MapControllers();
app.UseCors(x => x.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
app.Run();
